﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OODCRM.Common;

namespace OODCRM.ViewModel
{
    public static class RibbonModelHelper
    {
        /// <summary>
        /// Set the state for the feature change
        /// </summary>
        /// <param name="isEnabled">state</param>
        public static void SetState(bool? isEnabled, Feature feature)
        {
            if (!isEnabled.HasValue) return;
            if (isEnabled.Value)
            {
                EnableFeature(feature);
            }
            else
            {
                DisableFeature(feature);
            }
        }

        /// <summary>
        /// Relayout the UI and Ribbon controls to enable feature
        /// </summary>
        /// <param name="feature"></param>
        private static void EnableFeature(Feature feature)
        {
            switch (feature)
            {
                case Feature.SanPham:
                    RibbonModel.SanPham_Group.IsEnabled = true;

                    //
                    // Edit the commands
                    //
                    RibbonModel.SanPham_New.Command = new DelegateCommand(
                        RibbonModel.SanPham_NewExecuted,
                        RibbonModel.DefaultCanExecute
                        );
                    break;
                case Feature.ToChuc:
                    RibbonModel.ToChuc_Group.IsEnabled = true;

                    //
                    // Edit the commands
                    //
                    RibbonModel.ToChuc_New.Command = new DelegateCommand(
                        RibbonModel.ToChuc_NewExecuted,
                        RibbonModel.DefaultCanExecute
                        );
                    RibbonModel.ToChuc_Edit.Command = new DelegateCommand(
                        RibbonModel.ToChuc_EditExecuted,
                        RibbonModel.DefaultCanExecute
                        );
                    RibbonModel.ToChuc_Delete.Command = new DelegateCommand(
                        RibbonModel.ToChuc_DeleteExecuted,
                        RibbonModel.DefaultCanExecute
                        );

                    //
                    // Edit the view of ribbon
                    //
                    RibbonModel.ToChuc_Group.IsEnabled = true;
                    //RibbonModel.ToChuc_New.IsEnabled = true;
                    //RibbonModel.ToChuc_Edit.IsEnabled = true;
                    //RibbonModel.ToChuc_Delete.IsEnabled = true;

                    RibbonModel.VCL_Group.IsEnabled = true;
                    //RibbonModel.VCL_Add.IsEnabled = true;
                    //RibbonModel.VCL_Edit.IsEnabled = true;
                    //RibbonModel.VCL_Remove.IsEnabled = true;

                    RibbonModel.VDL_Group.IsEnabled = true;
                    //RibbonModel.VDL_Add.IsEnabled = true;
                    //RibbonModel.VDL_Edit.IsEnabled = true;
                    //RibbonModel.VDL_Remove.IsEnabled = true;

                    RibbonModel.GhiChu_Group.IsEnabled = true;
                    //RibbonModel.GhiChu_Add.IsEnabled = true;
                    //RibbonModel.GhiChu_Edit.IsEnabled = true;
                    //RibbonModel.GhiChu_Remove.IsEnabled = true;

                    RibbonModel.LienHe_Group.IsEnabled = true;
                    //RibbonModel.LienHe_New.IsEnabled = true;
                    //RibbonModel.LienHe_Edit.IsEnabled = true;
                    //RibbonModel.LienHe_Delete.IsEnabled = true;

                    RibbonModel.CoHoi_Group.IsEnabled = true;
                    //RibbonModel.CoHoi_New.IsEnabled = true;
                    //RibbonModel.CoHoi_Edit.IsEnabled = true;
                    //RibbonModel.CoHoi_Delete.IsEnabled = true;

                    RibbonModel.TinhHuong_Group.IsEnabled = true;
                    //RibbonModel.TinhHuong_New.IsEnabled = true;
                    //RibbonModel.TinhHuong_Edit.IsEnabled = true;
                    //RibbonModel.TinhHuong_Delete.IsEnabled = true;
                    break; 
                case Feature.ChienDich:
                    RibbonModel.ChienDich_Group.IsEnabled = true;
                    RibbonModel.ChienDich_New.Command = new DelegateCommand(
                        RibbonModel.ChienDich_NewExecuted, 
                        RibbonModel.DefaultCanExecute
                        );
                    RibbonModel.ChienDich_Edit.Command = new DelegateCommand(
                        RibbonModel.ChienDich_EditExecuted,
                        RibbonModel.DefaultCanExecute
                        );
                    RibbonModel.ChienDich_Delete.Command = new DelegateCommand(
                        RibbonModel.ChienDich_DeleteExecuted,
                        RibbonModel.DefaultCanExecute
                        );

                    RibbonModel.ChienDich_Group.IsEnabled = true;
                    RibbonModel.VCL_Group.IsEnabled = true;
                    RibbonModel.VDL_Group.IsEnabled = true;
                    RibbonModel.GhiChu_Group.IsEnabled = true;
                    RibbonModel.CoHoi_Group.IsEnabled = true;
                    break;     
                case Feature.LienHe:
                    RibbonModel.LienHe_Group.IsEnabled = true;
                    RibbonModel.LienHe_New.Command = new DelegateCommand(
                        RibbonModel.LienHe_NewExecuted, 
                        RibbonModel.DefaultCanExecute
                        );
                    RibbonModel.LienHe_Edit.Command = new DelegateCommand(
                        RibbonModel.LienHe_EditExecuted,
                        RibbonModel.DefaultCanExecute
                        );
                    RibbonModel.LienHe_Delete.Command = new DelegateCommand(
                        RibbonModel.LienHe_DeleteExecuted,
                        RibbonModel.DefaultCanExecute
                        );
                    break;
                case Feature.CoHoi:
                    RibbonModel.CoHoi_Group.IsEnabled = true;
                    RibbonModel.CoHoi_New.Command = new DelegateCommand(
                        RibbonModel.CoHoi_NewExecuted, 
                        RibbonModel.DefaultCanExecute
                        );
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// Relayout the UI and Ribbon controls to enable feature
        /// </summary>
        /// <param name="feature"></param>
        private static void DisableFeature(Feature feature)
        {
            switch (feature)
            {
                case Feature.SanPham:
                    RibbonModel.SanPham_Group.IsEnabled = false;
                    break;
                case Feature.ChienDich:
                    RibbonModel.ChienDich_Group.IsEnabled = false;
                    break;
                case Feature.ToChuc:
                    RibbonModel.ToChuc_Group.IsEnabled = false;
                    break;
                case Feature.LienHe:
                    RibbonModel.LienHe_Group.IsEnabled = false;
                    break;
                case Feature.CoHoi:
                    RibbonModel.CoHoi_Group.IsEnabled = false;
                    break;
                default:
                    break;
            }
        }

    }
}
